<?php
/**
 * 消息系统ACTION
 *
 * @author ananda
 */
class Action_Message_Index extends Action
{
    /**
     * 消息系统初始时的唯一入口
     */
    public function main()
    {
        return $this->ping();
    }

    /**
     * 返回拥有的函数
     */
    public function ping()
    {
        return implode(',', get_class_methods($this));
    }

    /**
     * 获取消息列表
     * @param <integer> $id
     * @return <string>
     */
    public function getOne($id)
    {
        return $this->controller->message->getOne($id);
    }

    /**
     * 获取某一玩家所关注者的消息列表
     * @param <integer> $user_id
     * @param <integer> $page
     * @param <integer> $limit
     * @return <string>
     */
    public function getUserList($user_id, $page, $limit)
    {
        $people = Com::glob()->people->gen($user_id, 'user');
        $data   = array('total' => $this->controller->message->getTotal($people),
                        'data'  => $this->controller->message->getList($people, $page, $limit));
        return $data;
    }

    /**
     * 获取某一玩家自己的消息列表
     * @param <integer> $user_id
     * @param <integer> $page
     * @param <integer> $limit
     * @return <string>
     */
    public function getSelfList($user_id, $page, $limit)
    {
        $people = Com::glob()->people->gen($user_id, 'self');
        $data   = array('total' => $this->controller->message->getTotal($people),
                        'data'  => $this->controller->message->getList($people, $page, $limit));
        return $data;
    }

    /**
     * 添加一条新的内容
     * @param <string> $user_id
     * @param <string> $sender
     * @param <integer> $createdat
     * @param <string> $data
     * @param <array> $follower
     * @return <integer>
     */
    public function postUserContent($user_id, $sender, $createdat, $data, $follower_id_list = array())
    {
        // 发送信息
        if (count($follower_id_list)) {
            $follower_it = new Model_Message_MassPeopleBuilder($follower_id_list);
            $follower_it->setCategory('user');
        } else {
            $follower_it = array();
        }

        $people = Com::glob()->people->gen($user_id, 'user');
        $id = $this->controller->message->post($people, $user_id, $sender, 'user', $createdat, $data, $follower_it);

        // 创建自已消息的页面索引
        $people = Com::glob()->people->gen($user_id, 'self');
        $this->controller->message->buildIndex($people, $id);
        return $id;
    }
}
